package com.mebs.model.reports.storedreport;

import com.mebs.model.logistics.Air;
import com.mebs.model.logistics.Ocean;
import com.mebs.model.logistics.Truck;
import com.mebs.model.reports.ReportType;
import com.mebs.model.Company;
import com.mebs.model.Project;
import static org.hibernate.proxy.HibernateProxyHelper.getClassWithoutInitializingProxy;
import org.jt.jet.annotation.Field;
import org.jt.jet.annotation.ArgumentType;

import javax.persistence.*;

/**
 * User: epb
 * Date: 05.02.2009
 * Time: 13:04:42
 */

@Entity()
@Table(name = "STORED_REPORT")
public class StoredReport {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "Id")
	private Long id;

	@ManyToOne(optional = true)
	@JoinColumn(name = "AirId")
	private Air air;

	@ManyToOne(optional = true)
	@JoinColumn(name = "OceanId")
	private Ocean ocean;

	@ManyToOne(optional = true)
	@JoinColumn(name = "TruckId")
	private Truck truck;

	@ManyToOne(optional = true)
    @JoinColumn(name = "CompanyId")
    private Company company;

    @ManyToOne(optional = true)
    @JoinColumn(name = "ProjectId")
    private Project project;

	@Column(name = "Url", nullable = false)
	private String url;

	@Column(name = "Name", nullable = false)
	private String name;

	@Column(name = "DisplayName", nullable = false, length = 250)
	private String displayName;

	@Column(name = "ReportType", nullable = false)
	private Integer reportType;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Air getAir() {
		return air;
	}

	public void setAir(Air air) {
		this.air = air;
	}

	public Ocean getOcean() {
		return ocean;
	}

	public void setOcean(Ocean ocean) {
		this.ocean = ocean;
	}

	public Truck getTruck() {
		return truck;
	}

	public void setTruck(Truck truck) {
		this.truck = truck;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public Integer getReportType() {
		return reportType;
	}

	public void setReportType(Integer reportType) {
		this.reportType = reportType;
	}

	@Transient
	public boolean isExcel() {
		return this.reportType == ReportType.ON_HAND_XLS_REPORT.getType()
				|| this.reportType == ReportType.M_REPORT.getType()
				|| this.reportType == ReportType.OPEN_SHIPMENT_REPORT.getType();
	}

	@Override
	public String toString() {
		return this.name;
	}

	@Override
	public int hashCode() {
		if (id == null) return super.hashCode();
		return id.hashCode();
	}

	@Override
	public boolean equals(Object o) {
		if (o == null) return false;
		if (this == o) return true;
		if (id == null) return false;
		if (getClassWithoutInitializingProxy(this) != getClassWithoutInitializingProxy(o))
			return false;
		final StoredReport that = (StoredReport) o;
		return id.equals(that.getId());
	}
}
